package cn.wolfcode.trip.base.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public abstract class DateUtil {
    private DateUtil(){}

    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String formatDate(Date date) {
        return format.format(date);
    }

    public static String intervalTimeMsg(Date beforeTime){
        Date now = new Date();
        long temp = (now.getTime() - beforeTime.getTime())/1000;
        if(temp < 60){
            return "刚刚";
        }else if(temp >= 60 && temp < 60*60){
            return temp/60 + "分前";

        }else if(temp >= 60*60 && temp < 60*60*24){
            return temp/(60*60) + "小时前";

        }else if(temp >= 60*60*24 && temp < 60*60*24*30){
            return temp/(60*60*24) + "天前";

        }else if(temp >= 60*60*24*30 && temp < 60*60*24*30*12){
            return temp/(60*60*24*30) + "个月前";

        }else if(temp >= 60*60*24*30*12 ){
            return temp/(60*60*24*30*12) + "年前";
        }
        return null;
    }
}
